<?php

/***  DOCUMENTATION LAYER

Last Update: May 2007
	
DESCRIPTION
	Simple demo of CeoCaptcha class
	
NOTES

	
***/

/* -- EDIT THIS SECTION ----------------------------------------------------- */
// Some Meta Data
$page_title = 'CeoCaptcha Demo';
$test_name = '';
$run_procedure = 1;

// Include Files
#require_once('path/fname.php');

/* -- END SECTION ----------------------------------------------------------- */



/* -- NO EDIT --------------------------------------------------------------- */
// Timer
$_tx0 = microtime();
// HEADER
$buffer = "<h1 style='margin:8px 0 0;'>$page_title</h1>";
#$buffer .= "<h4 style='margin:0 0 16px;'>$test_name</h4>";	// put script name here
/* -- END SECTION ----------------------------------------------------------- */



/* -- EDIT THIS SECTION ----------------------------------------------------- */
// Procedural Testing

if ( $run_procedure ) 
{
	#$buffer .= "<h4 style='margin:0; color:blue;'>Testing in Progess</h4>";
	
// Captcha Class
$debug = 0;
require_once('../captcha/captcha.class.php');
$Captcha = new CeoCaptcha($debug);
$Captcha->set_img_dir('../img_bin/');
$Captcha->collect_garbage_after = 6;
$Captcha->maxlifetime = 60;
$Captcha->maxtry = 3;

// make captcha
$Captcha->make('test');

// output captcha/results
if ( $Captcha->is_solved )
{
  $img_src = '../img_bin/prize.gif';
  $html = <<<HTML
<div class="prize">
<h3>congratulations!  you solved the captcha!</h2>
<a href="http://www.zombo.com"><img src="$img_src" alt="success!" /></a>
<p>click for your prize!</p>
</div>  
HTML;
}
elseif ( $Captcha->is_failed )
{
  $img_src = '../img_bin/failed.gif';
  $captcha_form = $Captcha->display();
  $html = <<<HTML
<div class="failed">
$captcha_form
<img src="$img_src" alt="failed" />
<p>try again</p>
</div>  
HTML;
}
elseif ( $Captcha->is_locked_out )
{
  $img_src = '../img_bin/locked.gif';
  $html = <<<HTML
<div class="locked_out">
<img src="$img_src" alt="success!" />
<p>sorry, you're locked out</p>
<h5>but just enter the url in the address bar again and you should get a new form</h5>
</div>  
HTML;
}
else
{
  $captcha_form = $Captcha->display();
  $html = <<<HTML
<div class="captcha_form">
$captcha_form
<p>solve the captcha, win a prize!</p>
</div>  
HTML;
}

  
	// add code below
  $buffer .= $html;
  
// stylesheet
$captcha_stylesheet = <<<CSS

.ceo_captcha
{
 width:300px;
 margin:20px 4px;
 padding:1em;
 border:8px solid #eee;
}
.ceo_captcha p.input
{
 padding:4px;
 text-align:center;
 background:#ffc;
 border:1px solid #cc9;
 border-width:1px 0;
}
img.captch_img
{
 display:block;
 margin:0 auto;
 padding:4px;
 border:2px solid #eeb;
}
p.input input
{
 margin:0 8px;
}
.ceo_captcha .refresh_block
{
 padding:4px;
 font-size:12px; 
 text-align:center;
}
.refresh_block input { font-size:12px; }

CSS;

$stylesheet = <<<CSS

<style type="text/css">
body
{
 font-family:sans-serif;
 margin:8px 10%;
}
img { border:none; }

.prize
{
 width:500px;
 margin:20px auto;
 text-align:center;
}
.prize h3
{
 color:green;
 margin:0 0 4px;
 font-weight:normal;
}

$captcha_stylesheet

</style>

CSS;

}

/* -- END SECTION ----------------------------------------------------------- */



/* -- NO EDITING NEEDED BELOW THIS LINE-------------------------------------- */
// output page

// Footer
$_txn = microtime();
$stx = number_format(((substr($_txn,0,9)) + (substr($_txn,-10)) - (substr($_tx0,0,9)) - (substr($_tx0,-10))),4); 
$footer = <<<HTML
<h4 style="margin:0; position:absolute; top:6px; right:6px; font-family:monospace; color:#36f; padding:4px; border:1px solid #36f; font-weight:normal; background:#f3f6ff;">
script completed in $stx s
</h4>
HTML;
$buffer .= $footer;

// Dump Html
$html = <<<HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>PHP Test: $page_title</title>
$stylesheet
</head>
<body>
$buffer
</body>
</html>
HTML;

echo $html;

?>
